// pages/index/page/blessing/blessing.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    windowWidth: 0, // 可使用窗口宽度
    windowHeight: 0, // 可使用窗口高度
    userTelephone: '',
    name: '',
    useraddress: '',
    userName:'',
  },

  send: function () {
    if (this.data.userName == '' || this.data.userTelephone == '' || this.data.useraddress == '') {
      wx.showToast({
        title: '请填写完整信息',
        icon: 'none'
      })
      return;
    }
    var that = this
    wx.request({
      url: 'https://xiaochengxu.fincoder.com/index.php/Home/WuFu/address',
      data: {
        myId: app.globalData.myId,
        name: this.data.userName,
        mobile: this.data.userTelephone,
        address: this.data.useraddress
      },
      method: 'POST',
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      success: function (res) {
    
        if (res.data.status==1){
            wx.showToast({
              title: '保存成功',
              icon: 'success',
              duration: 2000
            });
          }
      },
      fail: function () {
        wx.hideLoading()
        
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that=this
    console.log(options)
    wx.request({
      url: 'https://xiaochengxu.fincoder.com/index.php/Home/WuFu/myAddress',
      data: {
        myId: app.globalData.myId,
        uid: options.uid
      },
      method: 'POST',
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      success: function (res) {
          console.log(res)
        if (res.data.status == 1) {
          that.setData({
            useraddress: res.data.data.address,
            userName: res.data.data.name,
            userTelephone: res.data.data.mobile
          })
        }
      },
      fail: function () {
        wx.hideLoading()

      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    const vm = this
    vm.setData({
      statusBarHeight: getApp().globalData.statusBarHeight,
      titleBarHeight: getApp().globalData.titleBarHeight
    })
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: '#000000'
    });
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },
  q: function () {
    wx.navigateBack({ changed: true })
  },
  qq: function () {
    wx.switchTab({
      url: '/pages/index/index',
    });
  },
  toBlessingBox: function () {
    wx.navigateTo({
      url: '../blessingbox/blessingbox',
    });
  },
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
  userTelephone: function (e) {
    this.setData({
      userTelephone: e.detail.value
    })
  },
  useraddress: function (e) {
    this.setData({
      useraddress: e.detail.value
    })
  },
  userName: function (e) {
    this.setData({
      userName: e.detail.value
    })
  },

})